package com.wxd.dao;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class ConnectionManager {
	private ConnectionManager() throws PropertyVetoException {
		ds = new ComboPooledDataSource();
		ds.setDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		ds.setJdbcUrl("jdbc:sqlserver://127.0.0.1;DataBaseName=DateBase");
		ds.setUser("sa");
		ds.setPassword("1234");
		ds.setMinPoolSize(5);
		ds.setMaxPoolSize(20);
		ds.setAcquireIncrement(5);
		ds.setInitialPoolSize(5);
		
	}

	public static ConnectionManager getInstance() throws PropertyVetoException {
		if (instance == null){
			instance = new ConnectionManager();
		}
		return instance;
	}

	public final synchronized Connection getConnection() throws SQLException {
		return ds.getConnection();
	}

	private ComboPooledDataSource ds;
	private static ConnectionManager instance;
	
	
	public static void main (String args[]) throws Exception{
		Connection conn = getInstance().getConnection();
		Statement stmt = conn.createStatement();
		
		String sql = "SELECT * FROM login";
		ResultSet rs = stmt.executeQuery(sql);
		while(rs.next()){
			System.out.println(rs.getString("用户名"));
		}
	}
}
